package com.zsc.newbuds.mapper;

import com.zsc.newbuds.entity.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author D
 */
public interface UserMapper {

    /**
     * 根据手机号获取用户信息
     * @param phone
     * @return
     */
    @Select("select * from user where phone = #{phone}")
    User getUser(String phone);


    /**
     * 根据手机号获取用户信息
     * @param userId
     * @return
     */
    @Select("select * from user where userId = #{userId}")
    User getUserById(Integer userId);


    /**
     * 增加用户
     * @param user 用户信息
     */
    @Options(useGeneratedKeys = true,keyProperty = "userId")
    @Insert("insert into user(userName,password,phone,integral,avatar) VALUES(#{userName},#{password},#{phone},#{integral},#{avatar})")
    void addUser(User user);

    /**
     * 成为志愿者增加id
     * @param userId
     * @param volunteerId
     */
    @Update("update user set volunteer = #{volunteerId} where userId = #{userId}")
    void addVolunteerId(Integer userId, Integer volunteerId);


    /**
     * 修改密码
     * @param userId
     * @param password
     */
    @Update("update user set password = #{password} where userId = #{userId}")
    void updateUserPassword(Integer userId, String password);


    /**
     * 修改个人信息
     * @param userId
     * @param username
     * @param address
     */
    @Update("update user set userName = #{username},address= #{address} where userId = #{userId}")
    void updateUserInfo(Integer userId, String username, String address);


    /**
     * 修改用户手机号
     * @param userId
     * @param phone
     */
    @Update("update user set phone = #{phone} where userId = #{userId}")
    void updateUserPhone(Integer userId, String phone);

    /**
     * 增加用戶的積分
     * @param userId
     * @param integral
     */
    @Update("update user set integral = #{integral} where userId = #{userId}")
    void updateUserIntegral(Integer userId, int integral);

    /**
     * 獲取所有用戶信息
     * @return
     */
    @Select("select * from user")
    List<User> getUserList();

    /**
     * 根据志愿者ID获取用户ID
     * @param volunteerId
     * @return
     */
    @Select("select userId from user where volunteer = #{volunteerId}")
    int getUserId(int volunteerId);

    /**
     * 删除用户
     * @param userId
     */
    @Delete("delete from user where userId = #{userId}")
    void deleteUser(Integer userId);

    /**
     * 用户更改头像
     * @param id
     * @param avatar
     */
    @Update("update user set avatar = #{avatar} where userId = #{id}")
    void updateImage(Integer id,String avatar);

}
